//
//  PostImgUploadCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/14.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "PostImgUploadCell.h"

@implementation PostImgUploadCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.mainImageView.userInteractionEnabled = YES;
    [self.mainImageView addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.PostImgUploadCellBlock) {
            self.PostImgUploadCellBlock(PostImgUploadCellActionType_tap);
        }
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mainImageView pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
}

- (void)fillCellWithModel:(CommonMediaModel *)model {
    
    UIImage *placeHolder = [UIImage imageNamed:@"add_post_img"];
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:placeHolder];

    if (model.url.length > 3) {
        self.closeBtn.hidden = NO;
    } else {
        self.closeBtn.hidden = YES;
    }
}

- (IBAction)closeAction:(id)sender {
    
    if (self.PostImgUploadCellBlock) {
        self.PostImgUploadCellBlock(PostImgUploadCellActionType_del);
    }
}

@end
